import App from './App'
import store from './store/index.js'
import state from 'vuex'
// #ifndef VUE3
// 基地址
import {
	$http
} from '@escook/request-miniprogram'
uni.$http = $http
$http.baseUrl = 'https://api-hmugo-web.itheima.net'

// 请求拦截
$http.beforeRequest = function(options) {
	uni.showLoading({
		title: '数据加载中...'
	})
	console.log(options);
	if (options.url.includes('/my') && store.state.address.token) {
		options.header.Authorization = store.state.address.token
	}
}
// 响应拦截
$http.afterRequest = function(options) {
	uni.hideLoading()
	if (options.data && options.data.meta.status !== 200) return uni.$showMsg()
	console.log('相应拦截', options);
	// 给登录了的页面添加请求头
	// if(options.url.includes('/my'))
}

// 失败提示
uni.$showMsg = function(title = '出错啦...', duration = 2000) {
	uni.showToast({
		title,
		icon: 'error',
		duration
	})
}


import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App,
	store
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
